#include	"ParseCsvWarning.hpp"

ParseCsvWarning::ParseCsvWarning(std::list<std::string> listContent, int size)
  :_size(size), _listContent(listContent)
{
  
}

#include	<stdlib.h>

int				ParseCsvWarning::lengthInteger(int number)
{
  int	i = 0;
  while (number)
    {
      number /= 10;
      i++;
    }
  return (i - 1);
}

std::string			ParseCsvWarning::getStringFlags(int line)
{
  std::string	lineCurrent;
  std::string	lineInFile;
  std::string	flags;
  size_t		pos;
  size_t		pos2;
  int			nbLine;
  std::list<std::string>::iterator	it;

  for (it = this->_listContent.begin(); it != this->_listContent.end(); it++)
    {
      lineCurrent = (*it);
      pos = lineCurrent.find(";", 0);
      if (pos != std::string::npos)
	{
	  lineInFile = lineCurrent.substr(0, pos);
	  if ((nbLine = atoi(lineInFile.c_str())) == line)
	    {
	      pos2 = lineCurrent.find(";", pos);
	      flags.append(lineCurrent.substr(pos + 1, pos2 - lengthInteger(nbLine)));
	    }
	}
    }
    
  return (flags);
}

ObjectContain			*ParseCsvWarning::getContainLine(int line)
{
  std::string			lineCurrent;
  std::string			lineInFile;
  std::list<std::string>::iterator	it;
  size_t		pos;
  ObjectContain			*o;

  o = new ObjectContain(line);
  for (it = this->_listContent.begin(); it != this->_listContent.end(); it++)
    {
      lineCurrent = (*it);
      pos = lineCurrent.find(";", 0);
      if (pos != std::string::npos)
	{
	  lineInFile = lineCurrent.substr(0, pos);
	  if (atoi(lineInFile.c_str()) == line)
	    {
	      o->addItemList(lineCurrent);
	    }
	}
    }
  return (o);
}

std::list<ObjectContain *>	ParseCsvWarning::getListContainWarning()
{
  for (int i = 0; i < this->_size; i++)
    {
      this->_listContain.push_back(getContainLine(i + 1));
    }
  return (this->_listContain);
}

std::list<std::string>		ParseCsvWarning::getListFlags()
{
  for (int i = 0; i < this->_size; i++)
    {
      this->_listFlags.push_back(getStringFlags(i + 1));
    }
  return (this->_listFlags);
}

ParseCsvWarning::~ParseCsvWarning()
{
  
}

